<!--
 * @Author: Rain
 * @Date: 2021-11-24 22:29:52
 * @LastEditTime: 2023/10/12 21:33:32
 * @Description: Do Something
-->
<template>
  <div class="app-container w-full h-full overflow-hidden">
    <!--工具栏-->
    <div class="head-container flex flex-col w-full h-full">
      <div class="flex flex-end items-center">
        <!-- 搜索 -->
        <el-input
          v-model="query.name"
          clearable
          placeholder="姓名"
          style="width: 185px"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        />
        <el-input
          v-model="query.contact"
          clearable
          placeholder="联系方式"
          style="width: 185px"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        />
        <rrOperation :crud="crud" />
      </div>
      <crudOperation :permission="permission" />
      <div class="w-full flex-1 overflow-hidden">
        <el-table
          ref="table"
          v-loading="crud.loading"
          :data="crud.data"
          size="small"
          style="width: 100%"
          height="100%"
        >
          <el-table-column type="index" label="#" />
          <el-table-column prop="name" label="姓名" />
          <el-table-column prop="contact" label="联系方式" />
          <el-table-column prop="content" label="内容" />
          <el-table-column label="操作" width="150px" align="center">
            <template slot-scope="{ row }">
              <el-button
                type="primary"
                size="mini"
                @click="viewImg(row)"
              >查看图片</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <pagination />
    </div>
    <el-dialog title="" :visible.sync="dialogVisible" width="60%">
      <div class="flex w-full flex-col items-center">
        <el-image
          v-for="url in images"
          :key="url"
          :src="url"
          lazy
          style="margin-bottom: 10px"
        />
      </div>
      <div slot="footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import crudFeedback from '@/api/feedback'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import pagination from '@crud/Pagination'
import rrOperation from '@crud/RR.operation'
const defaultForm = {
  id: null,
  name: null,
  content: null,
  contact: null,
  images: null
}
export default {
  name: 'Feedback',
  components: { pagination, rrOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({
      title: '反馈建议',
      url: 'api/feedback',
      idField: 'id',
      sort: 'id,desc',
      crudMethod: { ...crudFeedback }
    })
  },
  data() {
    return {
      permission: {
        add: ['admin', 'feedback:add'],
        edit: ['admin', 'feedback:edit'],
        del: ['admin', 'feedback:del']
      },
      rules: {},
      queryTypeOptions: [
        { key: 'name', display_name: '姓名' },
        { key: 'contact', display_name: '联系方式' }
      ],
      dialogVisible: false,
      images: []
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    viewImg(row) {
      let { images } = row
      images = JSON.parse(images)
      this.images = images
      this.dialogVisible = true
    }
  }
}
</script>

<style scoped lang="scss">
.img {
  width: 200px;
}
::v-deep {
  .el-dialog__body {
    height: 500px;
    overflow: hidden auto;
    min-height: 400px;
  }
}
</style>
